#include <iostream>

using std::cout;
using std::endl;

class Stack {
public:
    Stack(size_t sz = 10)//默认参数将10带进来
    : _top(-1)
    , _sz(sz)
    , _data(new int[_sz]())
    {
    }

	bool empty() const	//判断栈是否为空
    {
#if 0
        if(-1 == _top)
        {
            return true;
        }
        else
        {
            return false;
        }
#endif

        return (-1 == _top);
    }

	bool full() const	//判断栈是否已满
    {
        return ((int)_sz == _top + 1);
    }

	void push(const int &value) //元素入栈
    {
        if(!full())//push元素的时候，栈是不是满的
        {
            _data[++_top] = value;
        }
        else
        {
            cout << "The stack is full" << endl;
            return;
        }
    }

	void pop()     //元素出栈
    {
        if(!empty())
        {
            --_top;
        }
        else
        {
            cout << "The stack is empty" << endl;
            return;
        }
    }

	int  top() const		//获取栈顶元素
    {
        return _data[_top];
    }

    ~Stack()
    {
        if(_data)
        {
            delete [] _data;
            _data = nullptr;
        }
    }

private:
    int _top;//栈顶指针
    size_t _sz;//栈的大小
    int *_data;//用来存栈中元素的
};

int main(int argc, char **argv)
{
    Stack st;
    cout << "栈是不是空的?" << st.empty() << endl;
    st.push(1);
    cout << "栈是不是满的?" << st.full() << endl;

    for(size_t idx = 2; idx != 14; ++idx)
    {
        st.push(idx);
    }

    cout << "栈是不是满的?" << st.full() << endl;
    while(!st.empty())
    {
        cout << st.top() << "  ";
        st.pop();
    }
    cout << "栈是不是空的?" << st.empty() << endl;

    return 0;
}

